/*
 * Flutter和Native交互通信
 * 
 */

import 'package:flutter/services.dart';

class FlutterChannel {
  static const _platform = MethodChannel("geely.smart.flutter.method");
  
  /// ### Flutter 调用 Native 方法
  /// 方法：`invokeNativeMethod`
  ///
  /// - 参数：
  ///
  /// `method`：方法名称
  ///
  /// `arguments`：参数
  /// - 示例：
  /// ```
  /// FlutterChannel.invokeNativeMethod("methodName",{"name":"jery","base":"shanghai"});
  /// ```
  static Future<Map<String, dynamic>> invokeNativeMethod(String method, [Map<String, dynamic> arguments]) async {
    var result;
    try {
      result = await _platform.invokeMethod(method, arguments);
    } on PlatformException catch (e) {
      print("invokeNativeMethod error：${e.message}");
    }
    return result;
  }

  void setMethodCallHandler (){
    _platform.setMethodCallHandler((call) {
      if(call.method == "method_one"){
        print(call.method);
      }
      else if(call.method == "method_two"){
        print(call.method);
      }
      return null;
    });
  }
  
  
}



